package com.corhyfar.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.corhyfar.beans.ProvinciaDTO;
import com.corhyfar.dao.ProvinciaDao;
import com.corhyfar.util.SQLConnection;

public class ProvinciaDaoImpl implements ProvinciaDao {

	Connection cn = null;
	PreparedStatement ps = null;
	ResultSet rs = null;

	@Override
	public List<ProvinciaDTO> listarProvincias() {
		List<ProvinciaDTO> lista = new ArrayList<ProvinciaDTO>();
		try {
			cn = new SQLConnection().GetConnection();
			String sql = "select * from DEPARTAMENTO";
			ps = cn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {

				lista.add(new ProvinciaDTO(rs.getInt(0), rs.getString(1), rs
						.getInt(2)));

			}
			ps.close();
			cn.close();
		} catch (SQLException e) {
			e.printStackTrace();

		}
		return lista;
	}

}
